﻿using NUnit.Framework;
using Spring.Context;
using Spring.Context.Support;

using System.Collections.Generic;
using OpenSda.Agilcont.Common.Business.Contracts;
using OpenSda.Agilcont.Common.Data.Entities;
using OpenSda.Agilcont.Common.Data.Contracts;
using OpenSda.Agilcont.Common.Business.Exceptions;

namespace OpenSda.Agilcont.Common.Business.SfContexts.NmTest
{
    [TestFixture]
    public class AgenciaBusinessTest : AbstractBaseDataTests
    {
        private IAgenciaBusiness target;
        public IAgenciaBusiness agenciaBusiness { set { target = value; } }
        private IUserData userData;
        public IUserData UserData { set { userData = value; } }
        
        [Test]
        [ExpectedException(typeof(AgenciaCannotBeNullException))]
        public void SaveWhenEmpresaIsNullTest()
        {
            target.Save(null);
        }

        [Test]
        public void SaveTest()
        {
            Agencia agencia = this.Save();
            Assert.IsNotNull(agencia.Identity);
        }
        private Agencia Save()
        {
            //Agencia u = agenciaData.GetAll()[0];
            return target.Save(new Agencia()
            {
                Codigo = "77pp14",
                NombreComun  = "asas",
                Direccion = "sasa"
                //EmpresaRef = u
            });
        }

        [Test]
        public void GetByIdTest()
        {
            this.GetById(new Agencia() { Codigo = "3" });
        }
        public IList<Agencia> GetById(object Id)
        {
            IList<Agencia> agencia = target.GetById(Id);
            return agencia;
        }

        public IList<Agencia> getListByFilter(string val)
        {
            IList<Agencia> agencia = target.GetListByFilter(val);
            return agencia;
        }

        public void EmpresaDeleteTests()
        {
            Agencia e = new Agencia();
            e.Codigo = "1";
            target.Delete(e);
        }
    }
}
